package siac.com.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import siac.com.configuracao.ConexaoHibernate;
import siac.com.entity.LocPais;
import siac.com.entity.LocProvincia;

public class LocProvinciaDao extends AbstractHibernateDao<LocProvincia> {

	public LocProvinciaDao() {
		super(LocProvincia.class);
	}

	@Override
	protected Session getSession() {
		return ConexaoHibernate.getSessionFactory().getCurrentSession();
	}

	public LocProvincia findCode(Object code) {
		Query query = this.getSession().getNamedQuery("LocPais.findByCode");
		query.setParameter("code", code);
		return (LocProvincia)query.uniqueResult();
	}

	public List<LocProvincia> findName(Object name) {
		Query query = this.getSession().getNamedQuery("LocPais.findByCode");
		query.setParameter("name", name);
		return query.list();
	}

	public List<LocProvincia> findStatus(Object status) {
		Query query = this.getSession().getNamedQuery("LocPais.findByCode");
		query.setParameter("status", status);
		return query.list();
	}

	public List<LocProvincia> findByPais(Object pais) {
		Query query = this.getSession().getNamedQuery("LocPais.findByCode");
		query.setParameter("pais", pais);
		return query.list();
	}

	public List<LocProvincia> findByCodePais(Object code) {
		LocPaisDao dao = new LocPaisDao();
		LocPais p = dao.findCode(code);
		return p.getProvincias();
	}
}
